
// 数字转换
export const numString = (num : number, precision : number = 2) => {
	if (num < 10000) {
		return `${num}`
	} else {
		let t = (num / 10000).toFixed(precision)
		let tt = t.substring(t.length - 1)
		if (tt === "0") {
			return `${(num / 10000).toFixed(0)}万`
		}
		return `${(num / 10000).toFixed(precision)}万`
	}
}

// 重排序列表
export const shuffleData = (sampleData : any) => {
	return sampleData.sort(() => Math.random() - 0.5);
}

import { reactive } from 'vue'
export function deepReactive<T extends object>(obj : T) : T {
	const result = reactive(obj) as any;
	for (const key in result) {
		if (Array.isArray(result[key])) {
			result[key] = reactive(result[key]);
			result[key].forEach((item : any, index : number) => {
				if (typeof item === 'object' && item !== null) {
					result[key][index] = deepReactive(item);
				}
			});
		} else if (typeof result[key] === 'object' && result[key] !== null) {
			result[key] = deepReactive(result[key]);
		}
	}

	return result;
}

// 时间 时分秒
export function formatTime(tSeconds : number) {
	const seconds = Number(tSeconds.toFixed(0))
	const hours = Math.floor(seconds / 3600);
	const minutes = Math.floor((seconds % 3600) / 60);
	const secs = seconds % 60;

	// 补零函数
	const pad = num => num.toString().padStart(2, '0');

	if (hours > 0) {
		return `${hours}:${pad(minutes)}:${pad(secs)}`;
	} else {
		return `${minutes}:${pad(secs)}`;
	}
}